/*
 * file:  main.h (main program to test Expr).
 * Author: Jeremy Johnson 
 * Date: 1/31/06
 *
 * Description:
 */

#include <iostream>
#include <string>
#include <map>
#include <list>
#include "../program.h"

using namespace std;


int main()
{
	map<string,int> T;
	map<string,int>::iterator p;

	Stmt *S1, *S2, *S3, *S4, *S5, *S6, *S7, *S8, *S9;
	Stmt *S10, *S11, *S12;
	Expr *N0, *N1, *N2, *N3, *E1, *E2, *E3;
	StmtList *SL1, *SL2, *SL3, *PSL;
	Program *P1;
	RAMCounter RC;

	//cout << "Testing Assignment Statement" << endl;
	N0 = new Number(0);
	N1 = new Number(1);
	N2 = new Number(2);
	N3 = new Number(3);

	//cout << "x := 0" << endl;
	S1 = new AssignStmt("x",N0);
	//S1->translate(T,RC);

	//cout << "y := 2" << endl;
	S2 = new AssignStmt("y",N2);
	//S2->translate(T,RC);


	//cout << "Symbol Table dump" << endl;
	//for (p=T.begin();p!=T.end();p++)
		//cout << p->first << "," << p->second << endl;
	//cout << endl;

	//cout << "x := 1" << endl;
	S3 = new AssignStmt("x",N1);
	//S3->translate(T,RC);

	//cout << "Symbol Table dump" << endl;
	//for (p=T.begin();p!=T.end();p++)
	//	cout << p->first << "," << p->second << endl;
	//cout << endl;


	//cout << "Testing If Statement" << endl;
	//cout << "if 0 then z := 0 else z := 1 fi" << endl;
	S4 = new AssignStmt("z",N0);
	S5 = new AssignStmt("z",N1);
	SL1 = new StmtList();	
	SL2 = new StmtList();	

	SL1->insert(S4);
	SL2->insert(S5);

	S6 = new IfStmt(N0,SL1,SL2);
	//S6->translate(T,RC);

	//cout << "Symbol Table dump" << endl;
	//for (p=T.begin();p!=T.end();p++)
	//	cout << p->first << "," << p->second << endl;
	//cout << endl;

	//cout << "if 1 then z := 0 else z := 1 fi" << endl;
	S7 = new IfStmt(N1,SL1,SL2);
	//S7->translate(T,RC);

	//cout << "Symbol Table dump" << endl;
	//for (p=T.begin();p!=T.end();p++)
	//	cout << p->first << "," << p->second << endl;
	//cout << endl;

	//cout << "Testing While Statement" << endl;
	//cout << "i := 3; s := 0" << endl;

	S8 = new AssignStmt("i",N3);
	//S8->translate(T,RC);
	S9 = new AssignStmt("s",N0);
	//S9->translate(T,RC);

	//cout << "Symbol Table dump" << endl;
	//for (p=T.begin();p!=T.end();p++)
	//	cout << p->first << "," << p->second << endl;
	//cout << endl;

	
	E1 = new Ident("i");
	E2 = new Plus(new Ident("s"), new Ident("i"));
	//cout << "i " << endl;
	//cout << "s+i " << endl;
	//E1->translate(T,RC);
	//E2->translate(T,RC); 

	S10 = new AssignStmt("s",E2);
	E3 = new Minus(new Ident("i"), new Number(1));
	S11 = new AssignStmt("i",E3);
	SL3 = new StmtList();
	SL3->insert(S11);
	SL3->insert(S10);

	S12 = new WhileStmt(E1,SL3);
	PSL = new StmtList();
	PSL->insert(S12);
	P1 = new Program(PSL,true);
	
	cout << "while i do s := s + i; i := i-1 od" << endl;

	P1->translate();
	P1->compile();
 	P1->dump();

	return 0;
}
